<template>
  <div class="registration-container">
    <form @submit.prevent="handleRegistration" class="registration-form">
      <h2>学生餐厅订单系统</h2>
      <p class="subtitle">创建您的餐厅管理账号</p>
      
      
      
      <div class="form-group">
        <label>账号：</label>
        <input
          type="text"
          v-model="username"
          placeholder="请设置管理员账号"
          required
        />
      </div>
      
      <div class="form-group">
        <label>密码：</label>
        <input
          type="password"
          v-model="password"
          placeholder="请设置登录密码"
          required
        />
      </div>
      
      <div class="form-group">
        <label>确认密码：</label>
        <input
          type="password"
          v-model="confirmPassword"
          placeholder="请再次输入密码"
          required
        />
      </div>
      
      
      <button type="submit" class="register-btn">立即注册 🍽️</button>
      
      <div class="login-link">
        已有账号？<router-link to="/">立即登录</router-link>
      </div>
    </form>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'

const router = useRouter()
const username = ref('')
const password = ref('')
const confirmPassword = ref('')


// 表单验证
const validateForm = () => {
  // 简单验证，实际项目中应使用更完善的验证
  
  if (!username.value) {
    ElMessage.warning('请设置管理员账号')
    return false
  }
  
  if (!password.value) {
    ElMessage.warning('请设置登录密码')
    return false
  } else if (password.value.length < 6) {
    ElMessage.warning('密码长度至少为6位')
    return false
  }
  
  if (password.value !== confirmPassword.value) {
    ElMessage.warning('两次输入的密码不一致')
    return false
  }
  
  
  return true
}

// 处理注册
const handleRegistration = () => {
  if (validateForm()) {
    // 模拟注册：存到 localStorage（实际项目用后端接口）
    localStorage.setItem('userInfo', JSON.stringify({ 
      username: username.value, 
      password: password.value 
    }))
    
    ElMessage.success('注册成功！正在跳转至登录页面...')
    setTimeout(() => {
      router.push('/')
    }, 1000)
  }
}
</script>

<style scoped>
.registration-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-image: linear-gradient(
      rgba(255, 255, 255, 0.15),
      rgba(255, 255, 255, 0.15)
    ),
    url("../../img/2.jpg"); /* 保持与登录页相同的背景图 */
  background-size: cover;
  background-position: center;
  font-family: 'PingFang SC', 'Helvetica Neue', sans-serif;
}

.registration-form {
  background: rgba(255, 245, 240, 0.3); /* 浅橙底色 */
  padding: 2.5rem;
  border-radius: 25px;
  box-shadow: 0 8px 32px rgba(231, 76, 60, 0.1);
  width: 420px;
  backdrop-filter: blur(12px);
  border: 2px solid #e74c3c; /* 番茄红边框 */
  transform: translateY(-10px);
}

h2 {
  text-align: center;
  color: #e67e22; /* 胡萝卜橙主标题 */
  margin-bottom: 0.8rem;
  font-size: 28px;
  letter-spacing: 2px;
  text-shadow: 2px 2px 4px rgba(230, 126, 34, 0.1);
  position: relative;
}

h2::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 3px;
  background: #ff6b6b; /* 珊瑚红装饰线 */
  border-radius: 2px;
}

.subtitle {
  text-align: center;
  color: #c0392b; /* 深红副标题 */
  margin-bottom: 2rem;
  font-size: 14px;
  opacity: 0.8;
}

.form-group {
  margin-bottom: 1.5rem;
}

label {
  display: block;
  margin-bottom: 0.8rem;
  color: #c0392b; /* 深红标签 */
  font-weight: 600;
  font-size: 15px;
}

input {
  width: 100%;
  padding: 14px;
  border: 2px solid #f1c40f; /* 向日葵黄边框 */
  border-radius: 12px;
  box-sizing: border-box;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: rgba(255, 255, 255, 0.9);
  font-size: 14px;
  color: #2c3e50;
}

input:focus {
  border-color: #e67e22; /* 胡萝卜橙焦点色 */
  box-shadow: 0 0 12px rgba(230, 126, 34, 0.3);
  background: rgba(255, 255, 255, 1);
}

.agreement-group {
  display: flex;
  align-items: center;
  margin-bottom: 1.5rem;
  font-size: 14px;
  color: #2c3e50;
}

.agreement-group input {
  margin-right: 8px;
  width: 16px;
  height: 16px;
}

.agreement-group a {
  color: #e67e22;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.agreement-group a:hover {
  color: #e74c3c;
  text-decoration: underline;
}

.register-btn {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, #e74c3c, #e67e22); /* 番茄红-胡萝卜橙渐变 */
  color: white;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1.5px;
  transition: 
    transform 0.2s ease,
    box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    opacity 0.2s ease;
  margin-top: 10px;
}

.register-btn:hover {
  transform: translateY(-2px);
  box-shadow: 
    0 6px 20px rgba(231, 76, 60, 0.25),
    0 4px 12px rgba(230, 126, 34, 0.2);
  opacity: 0.95;
}

.register-btn:active {
  transform: translateY(0);
  box-shadow: 
    0 3px 10px rgba(231, 76, 60, 0.2),
    0 2px 6px rgba(230, 126, 34, 0.15);
}

.register-btn::after {
  content: '🍽️'; /* 餐具符号 */
  margin-left: 8px;
  opacity: 0.8;
  transition: margin-left 0.3s ease;
}

.register-btn:hover::after {
  margin-left: 12px;
}

.login-link {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 14px;
  color: #2c3e50;
}

.login-link a {
  color: #e67e22;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}

.login-link a:hover {
  color: #e74c3c;
  text-decoration: underline;
}
</style>    